<template>
	<view class="page">
		<!-- 发票列表 -->
		<view class="invoice-list" v-if="list.length">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="content">
					<view class="title">
						<text>{{item.uname}}</text>
					</view>
					<view class="title">
						<text>{{item.idcard}}</text>
					</view>
				</view>
				<view class="edit flex-box" style="width:350rpx;">
					<view class="flex-box" @click="delList(item.id,index)" style="margin-right:10rpx;">
						删除
						<u-icon name="trash-fill" size="20" @tap="deleteAddress(item.id,index)"></u-icon>
					</view>
					<view class="flex-box" @click="toEdit(2,item)">
						编辑
						<text class="iconfont icon-edit1"></text>
					</view>
					
				</view>
			</view>
		</view>
		<u-empty v-else mode="data" marginTop="100" text="暂无数据"></u-empty>
		<!-- 添加按钮 -->
		<view class="add-btn">
			<view class="btn" @click="onInvoiceAdd">
				<!-- <text class="iconfont icon-jia"></text> -->
				<text>新增支付报关人</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
			};
		},
		onLoad(){
			
		},
		onShow(){
			this.getAlist()
		},
		methods:{
			// 删除
			delList(id,index){
				this.$u.api.idcardDelete({id})
				.then(res=>{
					if(res.status){
						this.list.splice(index,1)
						return
					}
					this.isNone = true
				})
				.catch(err=>{
					console.log(err);
					uni.showToast({
						icon: 'none',
						title: "网络异常，请稍后"
					})
				})
			},
			// 编辑
			toEdit(index,item){
				uni.navigateTo({
					url: '/pages/sub/declare/InvoiceAdd?type='+ index+'&item='+encodeURIComponent(JSON.stringify(item)),
				})
			},
			getAlist(){
				this.$u.api.idcardAlist().then(res=>{
					if(res.status){
						this.list = res.msg
					}
					
				})
				.catch(err=>{
					console.log(err);
					uni.showToast({
						icon: 'none',
						title: "网络异常，请稍后"
					})
				})
			},
			/**
			 * 发票添加点击
			 */
			onInvoiceAdd(){
				uni.navigateTo({
					url: '/pages/sub/declare/InvoiceAdd',
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'InvoiceList.scss';
</style>
